# 24. 寻找身高相近的小朋友

24

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

let lineCount = 0;
rl.on('line', function(line) {
    let selfHeight;
    let n;
    if (lineCount===0) {
        let arr = line.split(' ').map(Number);
        selfHeight = arr[0];
        n = arr[1];
    } else {
        let otherHeights = line.split(' ').map(Number);
        otherHeights.sort((a, b) => {
            let a1 = Math.abs((a - selfHeight));
            let b1 = Math.abs((b - selfHeight));
            if (a1 === b1) {
                return a - b;
            } else {
                return a1 - b1;
            }
        })
        console.log(otherHeights.join(' '));
    }
})

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29